<?php
/**
 * 商品风格关联表
 */
namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class ProductStyleJoin extends Model{

    protected $table = 'ln_product_style_join';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id',      //主键ID
        'product_id',         //产品uid
        'style_id',         //风格id
    ];

    public $timestamps = false;

    //获取风格或产品id获取所有关联id
    public function getStyleOrProductIds($where = ['style_id' => 1])
    {
        $key = array_keys($where)[0];
        if ($key == 'style_id') {
            $field = 'product_id';
        } else if ($key == 'product_id') {
            $field = 'style_id';
        } else return [];
        return $this->where($where)->pluck($field);
    }

}